import React from 'react'
// ===================================================================== 
import ExperimentalResult from './result/experimental-result'
import ExperimentalResultRight from './result/experimental-result-right'
import GraphicsInterpretation from './result/graphics-interpretation'
import ClinicSuggestionsTabs from './result/clinic-suggestions-tabs'
// ===================================================================== Declare
const { $fn, $Lazy } = window
// ===================================================================== Declare
const $cache = $Lazy.file(()=>import('#private/cache-api'))
// ===================================================================== 
class Index extends React.Component{
	state = { 
		selectedRows:[],
		info:{}
	}
	
	componentDidMount(){
		const { result_model } = this.props.top
		
		$cache.then( async f => {
			if([44011, 44012, 44020].includes(result_model)){
				// 药敏组合
				const yaoSelect = await f.getCache({ api:'drug_group' })
				// 结果
				const resultSelect = await f.getDisCache({ code: 65000 })
				// 
				this.setState({ yaoSelect, resultSelect })
			}
		})
	}
	componentWillUnmount(){
		this.setState = () => false
	}
	
	load = ({ info, rows, query }) => {
		this.setState({ rows, info, query })
		this?.cliRef?.load?.(info?.content)
		const { result_model } = query
		if([44021,44033].includes(result_model)){
			this.setState({
				doctor: this.props.searchRef().doctorData,
				record:this.props.searchRef().recordData
			})
		}
	}
	
	loading = bool => this.setState({ submitLoading: bool })
	
	clear = (status) => {
		this.setState({ info: { }})
		this.status = status
	}
	// 下发
	xiFaSend = exp => {
		this.resultRef?.xiFaSend?.(exp)
	}
	
	render(){
		const { submitLoading, info, rows, query, pagingLoading, yaoSelect, resultSelect, doctor, record } = this.state
		const { result_model, BingLiMode } = this.props.top
		const disabled = !$fn.hasObject(info) || pagingLoading
		const status = this.status || this.props.top.query.status
		const props = { disabled, submitLoading, rows, info, result:info.content, mode:result_model, query, status,
			onRefresh: ()=> {
				this.props.tableRef().onRefreshInfo()
				this.props.tableRef().onRefresh()
			},
			onRefreshTable: () => {
				this.props.tableRef().onRefresh()
			},
			onRefreshInfo: () => {
				this.props.tableRef().onRefreshInfo()
			}
		}
		const isBingLi = BingLiMode.includes(result_model)
		return (
			<>
				{ [44014, 44017, 44019, 44024, 44025, 44027, 44028].includes(result_model) && <GraphicsInterpretation {...props} /> }
				{ [44016].includes(result_model) && <ClinicSuggestionsTabs ref={ref=>this.cliRef=ref} {...props} />}
				{ ( isBingLi || [44011, 44012, 44020].includes(result_model) ) && (
					<ExperimentalResult
						ref 			= { ref => this.resultRef = ref }
						yaoSelect 		= { yaoSelect } 
						resultSelect	= { resultSelect } 
						doctor			= { doctor } 
						record			= { record }
						_this			= { this.props.top }
						isBingLi 		= { isBingLi }
						{...props} 
					/>
				) }
				{ [44015, 44018, 44031].includes(result_model) && <ExperimentalResultRight {...props}  /> }
			</>
		)
	}
}

export default Index